# 代码结果：
    # State changed to Initial State
    # Observer updated.

from abc import ABC, abstractmethod
from typing import List

# Observer 接口
class Observer(ABC):
    @abstractmethod
    def update(self) -> None:
        pass

# Subject 抽象类
class Subject:
    def __init__(self):
        self._observers = []

    def attach(self, observer: Observer) -> None:
        self._observers.append(observer)

    def detach(self, observer: Observer) -> None:
        self._observers.remove(observer)

    def notify_observers(self) -> None:
        for observer in self._observers:
           observer.update()

    def observers(self) -> List[Observer]:
        return self._observers

# ConcreteSubject 类
class ConcreteSubject(Subject):
    def __init__(self, state: str):
        super().__init__()
        self._state = state

    def change(self) -> None:
        print("State changed to", self._state)

# ConcreteObserver 类
class ConcreteObserver(Observer):
    def update(self) -> None:
        print("Observer updated.")

# 客户端使用示例
if __name__ == "__main__":
    subject = ConcreteSubject("Initial State")
    observer = ConcreteObserver()  # 创建观察者实例
    subject.attach(observer)  # 将观察者附加到主题
    subject.change()
    subject.notify_observers()  # 通知所有观察者
    subject.detach(observer)  # 从主题中移除观察者